package lab03.test13;

import java.sql.*;

public class Test {
    public static void main(String[] args) {
        Connection connection = null;
        Statement statement = null;
        ResultSet resultSet = null;
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        try {
            connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/java_2017?serverTimezone=UTC","root","123456");
            statement=connection.createStatement();
            statement.executeUpdate("insert t_students(id,stu_no,real_name,age,gender,department)values(1,'131','zhangshu',18,0,'旅游系')");
            statement.executeUpdate("insert t_students(id,stu_no,real_name,age,gender,department)values(2,'132','张来',19,1,'计算机系')");
            statement.executeUpdate("insert t_students(id,stu_no,real_name,age,gender,department)values(3,'133','刘郁',18,1,'计算机系')");
            statement.executeUpdate("insert t_students(id,stu_no,real_name,age,gender,department)values(4,'134','路路',17,0,'经济管理系')");
            statement.executeUpdate("insert t_students(id,stu_no,real_name,age,gender,department)values(5,'135','鲁直',20,0,'工商系')");
            statement.executeUpdate("insert t_students(id,stu_no,real_name,age,gender,department)values(6,'136','赵月',18,1,'中文系')");
            statement.executeUpdate("insert t_students(id,stu_no,real_name,age,gender,department)values(7,'137','顾之语',18,0,'外语系')");
            statement.executeUpdate("insert t_students(id,stu_no,real_name,age,gender,department)values(8,'138','楚楚',17,1,'土木工程系')");
            statement.executeUpdate("insert t_students(id,stu_no,real_name,age,gender,department)values(9,'139','万涂鸦',17,1,'烹饪系')");
            statement.executeUpdate("insert t_students(id,stu_no,real_name,age,gender,department)values(10,'140','王火',19,0,'旅游系')");
            resultSet=statement.executeQuery("SELECT * FROM t_students ");
            while (resultSet.next()){
                System.out.print(resultSet.getString(1)+" ");
                System.out.print(resultSet.getString(2)+" ");
                System.out.print(resultSet.getString(3)+" ");
                System.out.print(resultSet.getString(4)+" ");
                System.out.print(resultSet.getString(5)+" ");
                System.out.print(resultSet.getString(6)+" ");
                System.out.print(resultSet.getString(7)+" ");
                System.out.print(resultSet.getString(8)+" ");
                System.out.print(resultSet.getString(9)+" ");
                System.out.print(resultSet.getString(10)+" ");
                resultSet=statement.executeQuery("delete from t_students where id=5");
                resultSet=statement.executeQuery("update t_students set department='信息与工程学院' where ");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
